package com.lanji.sensitive.controller;

import com.lanji.sensitive.entity.request.DocRequest;
import com.lanji.sensitive.entity.response.SensitiveDataRes;
import com.lanji.sensitive.entity.result.ResultData;
import com.lanji.sensitive.services.SensitiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Twilight
 * @desc
 * @createTime 2021-01-27-20:18
 */
@RestController
@Slf4j
@RequestMapping("/senstive")
@Api(tags = "敏感词")
public class SensitiveController {

    @Autowired
    private SensitiveService sensitiveService;

    @PostMapping("/parse")
    @ApiOperation("标记")
    public ResultData<List<SensitiveDataRes>> sensitiveParse(@RequestBody DocRequest docRequest) {
        if (StringUtils.isEmpty(docRequest.getDocStr())) {
            return ResultData.fail("请输入文字！");
        }
        List<SensitiveDataRes> sensitiveDatumRes = sensitiveService.parseDoc(docRequest);
        return ResultData.success(sensitiveDatumRes);
    }

}
